

//var api_base_url = 'http://localhost:8080/Tuzhan_Server/api/';
var api_base_url = 'http://139.196.20.115:8080/sd_server/server/';
var api_base_url1 = 'http://139.196.20.115:8080/sd_server/';
var api_login_url = 'http://139.196.20.115:8080/sd_server/open/';


var cookie_expire =20;

function initSimpleNavBar(){
     $(".navbar").load('../component/navbar.html');
}


function initAdminNavBar(){
    $(".navbar").load('../component/admin-nav-bar.html');
}



function initSideBar(cat,item){
	$(".sidebar-nav").load('../component/sidebar.html',function(){
			$("#"+item).addClass('active');
			$("#"+cat).removeClass('collapsed');
			$('#'+item).parents('ul').addClass('in');
	});
};

function initCommon(){
    $(".common").load('../common/common.html');
}


function getparastr(strname)
 {
  var hrefstr,pos,parastr,para,tempstr;
  hrefstr = window.location.href;
  pos = hrefstr.indexOf("?")
  parastr = hrefstr.substring(pos+1);
  para = parastr.split("&");
  tempstr="";
  for(i=0;i<para.length;i++)
  {
   tempstr = para[i];
   pos = tempstr.indexOf("=");
   if(tempstr.substring(0,pos) == strname)
   {
    return tempstr.substring(pos+1);
    }
  }
  return null;
 }


$.ajaxSetup( {
	cache:false
});


$(document).ajaxStart(onStart)
.ajaxComplete(onComplete)
.ajaxSuccess(onSuccess)
.ajaxError(onError);

function onStart(event) {
   
}
function onComplete(event, xhr, settings) {
	
	/*
	var tempvalue = event.currentTarget.URL.indexOf("sign-in.html");
	var dengluyeFlag = (tempvalue !=-1);
	if(!dengluyeFlag){
		var tempSessionid = $.cookie("sessionId");
		if(tempSessionid == undefined || tempSessionid == "null" || tempSessionid == "" ){
			//
			$("#cuowu-msg").text("客户端的sessionId为空，session过期");
			$("#cuowuModal").modal();
			return false;
		}
	}
	*/
}

function onSuccess(event, xhr, settings) {
	
	//session  过期 跳转到登录
	if(settings.dataType=='json'&& xhr.responseJSON.code=='401'){
		var errorCode  = xhr.responseJSON.code ;
		var errorMsg = xhr.responseJSON.msg;
		$("#cuowu-code").text(errorCode);
		$("#cuowu-msg").text(errorMsg);
		$("#cuowuModal").modal();
		return false;
	//	window.location.href="../account/sign-in.html";
		return;
	}
	
	//延长cookie
	var date = new Date();
	date.setTime(date.getTime() + (cookie_expire * 60 * 1000));
	
	$.cookie("sessionId",$.cookie("sessionId"),{ path: '/',expires: date  } ); 
	$.cookie("userId",$.cookie("userId"),{ path: '/',expires: date  } );
	$.cookie("clientType",$.cookie("clientType"),{ path: '/',expires: date  } );
	//自定义错误
	if(settings.dataType=='json'&& xhr.responseJSON.code!='200'){
		var errorCode  = xhr.responseJSON.code ;
		var errorMsg = xhr.responseJSON.msg
		$("#cuowu-code22").text(errorCode);
		$("#cuowu-msg22").text(errorMsg);
		$("#cuowuModal22").modal();
	}
}

function onError(event,xhr,options,exc){
	
	$("#cuowu-msg22").text("服务器端出现错误");
	$("#cuowuModal22").modal();
	
}


